import {
  queryCompanyItemListService,
  queryBrandItemListService,
  queryOrgItemListService,
  queryStockItemListService,
  // getCenterItemListService,
} from '@api/public'

// 存量溢出管理查询条件
export const initFormItemList = (optionsObj) => {
  return [
    {
      prop: 'processingStatusList',
      label: '处理状态',
      type: 'select',
      clearable: true,
      multiple: true,
      options: optionsObj.processingStatus,
    },
    {
      prop: 'categoryUuids',
      label: '分类名称',
      type: 'category'
    },
    {
      prop: 'isLogistic',
      label: '是否物流中心',
      type: 'select',
      clearable: true,
      options: optionsObj.isLogistic,
    },
    {
      prop: 'companyId',
      label: '分公司',
      type: 'select',
      remote: true,
      remoteMethod: queryCompanyItemListService,
      paramKey: 'companyName',
    },
    {
      prop: 'areaId',
      label: '区域',
      type: 'selectFilter',
      filterable: true,
      clearable: true,
      allOptions: optionsObj.area,
      options: [],
    },
    {
      prop: 'centerId',
      label: '归属中心',
      type: 'select',
      filterable: true,
      clearable: true,
      options: optionsObj.centerList || [],
    },
    {
      prop: 'stockAttrList',
      label: '存量溢出属性',
      type: 'select',
      multiple: true,
      clearable: true,
      options: optionsObj.stockAttr,
    },
    {
      prop: 'processingUserName',
      label: '处理人',
      type: 'input',
    },
    {
      prop: 'brandUuid',
      label: '品牌',
      type: 'select',
      remote: true,
      remoteMethod: queryBrandItemListService,
      paramKey: 'brandName',
    },
    {
      prop: 'departmentId',
      label: '归属部门',
      type: 'select',
      remote: true,
      remoteMethod: queryOrgItemListService,
      paramKey: 'orgName',
    },
    {
      prop: 'enumTempProduct',
      label: '商品大类',
      type: 'select',
      clearable: true,
      options: optionsObj.enumTempProducList,
    },
    {
      prop: 'skuNo',
      label: '商品编码',
      type: 'input',
    },
    {
      prop: 'productName',
      label: '商品名称',
      type: 'input',
    },
    {
      prop: 'processingType',
      label: '处理方式',
      type: 'select',
      clearable: true,
      options: optionsObj.processingType,
    },
    {
      prop: 'planSolveUpdateDate',
      label: '预计解决日期',
      type: 'datePicker'
    },
    {
      prop: 'isSolveDateModify',
      label: '是否变化',
      placeholder: '预计解决日期是否变化',
      type: 'select',
      clearable: true,
      options: optionsObj.isSolveDateModify,
    },
    // statisticsBeginDate statisticsEndDate
    {
      prop: 'statisticsDate',
      label: '统计日期',
      type: 'datePicker',
    },
    {
      prop: 'planDigestionRegionList',
      label: '预计消化区间',
      type: 'select',
      multiple: true,
      clearable: true,
      options: optionsObj.planDigestionRegion,
    },
    {
      prop: 'stockId',
      label: '仓位',
      type: 'select',
      remote: true,
      remoteMethod: queryStockItemListService,
      paramKey: 'stockName',
    },
    {
      prop: 'supplyName',
      label: '供应商',
      type: 'input',
    },
    {
      prop: 'isSeason',
      label: '是否季节性商品',
      type: 'select',
      clearable: true,
      options: optionsObj.isLogistic,
    },
    {
      prop: 'qualityGuaranteePeriodType',
      label: '保质期类型',
      type: 'select',
      clearable: true,
      options: optionsObj.qualityGuaranteePeriodType,
    },
    {
      prop: 'productStockAttribute',
      label: '存量属性',
      type: 'select',
      clearable: true,
      options: optionsObj.productStockAttribute,
    },
    {
      prop: 'isSolutionReasonable',
      label: '是否合理',
      type: 'select',
      clearable: true,
      options: optionsObj.isLogistic,
    },
    {
      prop: 'stockDate',
      label: '新做库存日期',
      type: 'datePicker'
    },
    {
      prop: 'unStockDate',
      label: '不做库存日期',
      type: 'datePicker'
    },
  ]
}
// 存量溢出管理列表
export const initTableColumns = (parent) => {
  return [
    {
      title: '统计日期',
      key: 'dataDate',
    },
    {
      title: '更新日期',
      key: 'updateDate',
    },
    {
      title: '处理状态',
      key: 'processingStatusStr',
      width: 90
    },
    {
      title: '处理部门',
      key: 'processDepartmentName',
    },
    {
      title: '归属部门',
      key: 'attributionDepartmentName',
    },
    {
      title: '归属中心',
      key: 'attributionCenterName',
    },
    {
      title: '分公司',
      key: 'companyName',
    },
    {
      title: '区域',
      key: 'itemAreaStr',
      width: 90
    },
    {
      title: '商品大类',
      key: 'enumTempProductTypeStr',
    },
    {
      title: '商品类型',
      key: 'productTypeStr',
    },
    {
      title: 'SKU编码',
      key: 'skuNo',
      width: 90
    },
    {
      title: '商品名称',
      key: 'productName',
    },
    {
      title: '规格',
      key: 'specDetail',
    },
    {
      title: '计量单位',
      key: 'unitName',
      width: 90
    },
    {
      title: '是否定制',
      key: 'canCustomStr',
      width: 90
    },
    {
      title: '件装数量',
      key: 'pieceAmount',
      width: 90
    },
    {
      title: '品牌',
      key: 'brandName',
    },
    {
      title: '是否做库存',
      key: 'stockFlagStr',
    },
    {
      title: '下限',
      key: 'lowerLimit',
      width: 80
    },
    {
      title: '上限',
      key: 'upperLimit',
      width: 80
    },
    {
      title: '上下限调整日期',
      key: 'limitUpdateTime',
      width: 150
    },
    {
      title: '本区域物流中心下限',
      key: 'areaLowerLimit',
      width: 150
    },
    {
      title: '本区域物流中心上限',
      key: 'areaUpperLimit',
      width: 150
    },
    {
      title: '实物库存',
      key: 'productStock',
      width: 80
    },
    {
      title: '实物可售库存',
      key: 'canSendAmount',
      width: 100
    },
    {
      title: '物流中心实物可售库存',
      key: 'logisticCenterCanSendAmount',
      width: 150
    },
    {
      title: '预计消化天数',
      key: 'planDigestionDays',
      width: 100
    },
    {
      title: '预计消化区间',
      key: 'planDigestionRegionStr',
      width: 100
    },
    {
      title: '区域预计消化天数',
      key: 'areaPrepareCostDays',
      width: 130
    },
    {
      title: '区域预计消化区间',
      key: 'areaplanDigestionRegion',
      width: 130
    },
    {
      title: '占用库存',
      key: 'occupation',
    },
    {
      title: '成本价',
      key: 'costPrice',
    },
    {
      title: '库存金额',
      key: 'stockPrice',
    },
    {
      title: '本公司近三个月销量',
      key: 'threeMonthsOutbound',
      width: 140
    },
    {
      title: '本区域近三个月销量',
      key: 'areaOutboundThreeMonths',
      width: 140
    },
    {
      title: '全集团三个月销量',
      key: 'groupThreeMonthSaleTotal',
    },
    {
      title: '存量溢出属性',
      key: 'stockAttrStr',
    },
    {
      title: '新做库存时间',
      key: 'newestStockTime',
    },
    {
      title: '不做库存时间',
      key: 'lastUnstockTime',
    },
    {
      title: '处理方式',
      key: 'processingTypeStr',
    },
    {
      title: '处理备注',
      key: 'remark',
    },
    {
      title: '仓位',
      key: 'stockName',
    },
    {
      title: '预计解决日期-首次',
      key: 'planSolveDate',
      width: 140
    },
    {
      title: '预计解决日期-上次',
      key: 'planSolveDateLastmodify',
      width: 140
    },
    {
      title: '预计解决日期是否变化',
      key: 'isSolveDAteModifyStr',
      width: 150
    },
    {
      title: '处理人',
      key: 'processingUserName',
    },
    {
      title: '处理时间',
      key: 'processingTime',
    },
    {
      title: '商品管理区域',
      key: 'productManageAreaStr',
    },
    {
      title: '四级类编码',
      key: 'categoryNo',
    },
    {
      title: '四级类名称',
      key: 'categoryName',
    },
    {
      title: '是否物流中心',
      key: 'isLogisticStr',
    },
    {
      title: '是否季节性商品',
      key: 'isSeasonStr',
    },
    {
      title: '存量属性',
      key: 'productStockAttributeStr',
    },
    {
      title: '主供应商',
      key: 'mainSupplyName',
    },
    {
      title: '供应商数量',
      key: 'supplyNum ',
      render: (h, { row }) => {
        return <a onClick={() => parent.handleShowSpplier(row)}>{ row.supplyNum }</a>
      }
    },
    {
      title: '上架期',
      key: 'putOnPeriod',
    },
    {
      title: '下架期',
      key: 'putOffPeriod',
    },
    {
      title: '保质期类型',
      key: 'qualityGuaranteePeriodTypeStr',
    },
    {
      title: '保质期天数',
      key: 'qualityGuaranteePeriodDays',
    },
    {
      title: '产生原因',
      key: 'causes',
    },
    {
      title: '产生原因备注',
      key: 'causesRemark',
    },
    {
      title: '产生原因填写人',
      key: 'causesCreater',
    },
    {
      title: '审批人',
      key: 'auditUserName',
    },
    {
      title: '审批意见',
      key: 'auditOpinion',
    },
    {
      title: '审批时间',
      key: 'auditTime',
    },
    {
      title: '解决措施是否合理',
      key: 'isSolutionReasonableStr',
    },
    {
      title: '复核意见',
      key: 'reviewOpinion',
    },
    {
      title: '复核人',
      key: 'reviewUserName',
    },
    {
      title: '复核部门',
      key: 'reviewDeptName',
    },
    {
      title: '复核时间',
      key: 'reviewTime',
    },
    {
      title: '操作',
      key: 'dealLog',
      fixed: 'right',
      width: '100',
      render: (h, { row }) => {
        return <el-button
          size="mini"
          type="text"
          onClick={() => parent.handleShowLog(row)}
        >日志</el-button>
      }
    },
  ]
}
// 出入库记录
export const initRecordColumns = (parent) => {
  return [
    {
      title: '单据名称',
      key: 'recordName',
    },
    {
      title: '单据状态',
      key: 'stateName',
    },
    {
      title: '库存公司',
      key: 'stockCompanyName',
    },
    {
      title: '单据类型',
      key: 'recordTypeName',
    },
    {
      title: '单据日期',
      key: 'recordDate',
    },
    {
      title: '单据时间',
      key: 'recordTime',
    },
    {
      title: '单据号',
      key: 'recordNo',
    },
    {
      title: '商品代码',
      key: 'skuNo',
    },
    {
      title: '商品名称',
      key: 'productName',
    },
    {
      title: '规格型号',
      key: 'specialDetail',
    },
    {
      title: '计量单位',
      key: 'unitName',
    },
    {
      title: '仓位',
      key: 'stockName',
    },
    {
      title: '数量',
      key: 'stockAmount',
    },
    {
      title: '是否越库',
      key: 'isCrossStockStr',
    },
    {
      title: '上游单据号',
      key: 'relRecordNo',
      render: (h, { row, index }) => {
        return <el-popover
          loading={parent.detailLoading}
          onShow={() => parent.queryStockRecordDetail(row, index)}
          placement="left"
          width="300"
          title="单据相关信息"
          trigger="hover">
          <ul>
            { row.detailList && row.detailList.map(item => <li style="margin-left: 20px" key={item.label}>{item.label}：{item.value}</li>) }
          </ul>
          <a slot="reference">{row.relRecordNo}</a>
        </el-popover>
      }
    },
    {
      title: '供应商/客户代码',
      key: 'supplyOrCustomerCode',
      width: '120',
    },
    {
      title: '供应商/客户名称',
      key: 'supplyOrCustomerName',
      width: '120',
    },
    {
      title: '供应商分类',
      key: 'supplierClassifyName',
    },
  ]
}

// 区域数据
export const AREA_DATA_COLUMNS = [
  {
    title: 'SKU编码',
    key: 'skuNo',
    sortable: true,
    width: 100
  },
  {
    title: '商品名称',
    key: 'productName',
    sortable: true,
    width: 100
  },
  {
    title: '规格',
    key: 'specialDetail',
    sortable: true,
  },
  {
    title: '公司名称',
    key: 'companyName',
    sortable: true,
    width: 100
  },
  {
    title: '是否物流中心',
    key: 'isLogisticCenter',
    width: 110
  },
  {
    title: '实物库存',
    key: 'productStock',
  },
  {
    title: '实物可售库存',
    key: 'canSendAmount',
    width: 110
  },
  {
    title: '上限',
    key: 'upperLimit',
  },
  {
    title: '下限',
    key: 'lowerLimit',
  },
  {
    title: '预计消化天数',
    key: 'planDigestionDays',
    sortable: true,
    width: 120
  },
  {
    title: '本公司近三个月销量',
    key: 'companyThreeMonthsSaleTotal',
    sortable: true,
    width: 150
  },
  {
    title: '本区域近三个月销量',
    key: 'areaThreeMonthsSaleTotal',
    sortable: true,
    width: 150
  },
]
// 备注设置表格
export const REMARK_TABLE_COLUMNS = [
  {
    title: '字段名称',
    key: 'typeStr',
    width: 100
  },
  {
    title: '字典值',
    key: 'label',
    width: 100
  },
  {
    title: '备注提示文案',
    key: 'remark',
    type: 'input',
    width: 300
  },
]
// 导入批量维护查询条件
export const BATCH_FORM_ITEM_LIST = [
  {
    label: '单据号',
    prop: 'batchNo',
    type: 'input',
  },
  {
    label: '提交部门',
    prop: 'departmentName',
    type: 'input'
  },
  {
    label: '制单时间',
    prop: 'createdAt',
    type: 'datePicker',
    datePickerType: 'datetimerange'
  },
  {
    label: '制单人',
    prop: 'createdUserName',
    type: 'input'
  },
]
// 导入批量维护
export const BATCH_TABLE_COLUMNS = [
  {
    title: '单据号',
    key: 'batchNo',
    width: '200'
  },
  {
    title: '制单人',
    key: 'createdUserName',
    width: '90'
  },
  {
    title: '制单时间',
    key: 'createdAt'
  },
  {
    title: '提交部门',
    key: 'departmentName'
  },
  {
    title: '所属区域',
    key: 'areaName'
  },
  {
    title: '单据状态',
    key: 'batchStatusName'
  },
  {
    title: '失败行数',
    key: 'validErrorCount'
  },
  {
    title: '成功行数',
    key: 'validSuccessCount'
  },
]
